package com.puccampinas.finalproject.core.controller;

import java.util.ArrayList;
import java.util.List;

import com.puccampinas.finalproject.core.persistence.abstracts.ActivitiesDAO;
import com.puccampinas.finalproject.core.persistence.entity.Activity;
import com.puccampinas.finalproject.core.persistence.entity.Step;
import com.puccampinas.finalproject.core.persistence.entity.enums.ActivityType;

public class ActivityController {
	
	public static List<Activity> getActivities() {
		ActivitiesDAO activitiesDAO = ActivitiesDAO.getDAO();
		return activitiesDAO.findAll();
	}
	
	public static List<Activity> getActivities(Long partnerId) {
		ActivitiesDAO activitiesDAO = ActivitiesDAO.getDAO();
		return activitiesDAO.findAll(partnerId);
	}
	
	public static List<Activity> getActivities(String type) {
		ActivitiesDAO activitiesDAO = ActivitiesDAO.getDAO();
		List<Activity> atividades = new ArrayList<Activity>();
		
		ActivityType tp = convertToType(type);
		if (tp.equals(ActivityType.CONTEST)) {
			atividades = activitiesDAO.getContests();
		} else if (tp.equals(ActivityType.SORTITION)) {
			atividades = activitiesDAO.getSortitions();
		} else if (tp.equals(ActivityType.CAMPAIGN)) {
			atividades = activitiesDAO.getCampaigns();
		} else {
			atividades = activitiesDAO.getEvents();
		}
		
		return atividades;
	}
	
	
	private static ActivityType convertToType(String type) {
		return ActivityType.valueOf(type.toUpperCase());
	}
	
	public static List<Step> getSteps(Long atividadeId) {
		ActivitiesDAO activitiesDAO = ActivitiesDAO.getDAO();
		return activitiesDAO.getSteps(atividadeId);
	}
	
	public static Boolean participar(Long userId, Long atividadeId) {
		ActivitiesDAO activitiesDAO = ActivitiesDAO.getDAO();
		return activitiesDAO.participar(userId, atividadeId);
	}
	
	public static Boolean desistir(Long userId, Long atividadeId) {
		ActivitiesDAO activitiesDAO = ActivitiesDAO.getDAO();
		return activitiesDAO.desistir(userId, atividadeId);
	}
	
	public static Boolean participa(Long userId, Long atividadeId) {
		ActivitiesDAO activitiesDAO = ActivitiesDAO.getDAO();
		return activitiesDAO.participa(userId, atividadeId);
	}
}
